package com.cims.bo.land;

import java.util.List;

import com.cims.common.exception.BoException;
import com.cims.common.vo.Customer;
import com.cims.common.vo.GravePurchased;
import com.cims.common.vo.Land;
import com.cims.common.vo.OrderItem;
import com.cims.dao.hibernate.HibernateUtil;
import com.cims.dao.land.LandDAO;
import com.cims.dao.land.LandDAOImpl;

public class LandBOImpl implements LandBO {

	private LandDAO dao = new LandDAOImpl();

	@Override
	public Land findLindById(int landId) {
		try {
			return dao.findLandById(landId);
		} catch (Exception ex) {
			return null;
		}
	}

	@Override
	public List<OrderItem> getListLandOfCustomer(int customerId)
			throws BoException {
		try {
			List<OrderItem> listLand = dao.getListLandOfCustomer(customerId);
			return listLand;
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public List<GravePurchased> getListGravePurchasedOfCustomer(int customerId)
			throws BoException {
		try {
			List<GravePurchased> listG = dao
					.getListGravePurchasedOfCustomer(customerId);
			return listG;
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public boolean assignGraveToLand(OrderItem o, GravePurchased graveP)
			throws BoException {
		try {
			return dao.assignGraveToLand(o, graveP);
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public Customer findLandOwner(int itemId) {
		try {
			OrderItem order = HibernateUtil.findOne(OrderItem.class,
					"from OrderItem where ItemId=" + itemId);
			if (order != null) {
				return order.getCustomer();
			} else {
				return null;
			}
		} catch (Exception ex) {
			return null;

		}
	}
}
